﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MudClassSkeleton;
using System.Data;
using System.Data.SqlClient;

namespace WcfBusinessLogic.Model
{
    public class WorldContainer
    {
        // This is where all the code for our game world will stem from.
        // This should contain the Muds Application State
        private List<Realm> Realms = new List<Realm>();
        public GameManager GM = null;
        //public Model.ServerTick tick = null;
        //public Model.ServerTick tick = new ServerTick();
        public WorldContainer()
        {
            // Here is where we will load all our objects and start all our threads.
            //tick = new ServerTick();
            RecordManager RM = new RecordManager();
            try
            {
                /*
                Realm newRealm = new Realm(DT.Rows[0]);
                Realms.Add(newRealm);
                 */
                DataTable DT = RM.SendReadRequest("mspGetRealm", new List<SqlParameter>());
                foreach(DataRow row in DT.Rows)
                {
                    Realm newRealm = new Realm(row);
                    newRealm.ResolveTransitionReferences();
                    Realms.Add(newRealm);
                }
                GM = new GameManager(Realms);
                KeywordManager.GetKeyword("look");
                //GM.AddCharacter("2");
                //PlayerCharacter pc = GM.GetCharacter("2");
                //Model.HubCommunication.broadcast("Server", pc.ID.ToString(), "main");

            }
            catch(Exception EE)
            {
                Console.WriteLine(EE.StackTrace);
                Model.HubCommunication.broadcast("Server", EE.StackTrace.ToString(), "main");
                return;
            }
        }

            public List<Realm> getRealms()
            {
                return Realms;
            }
    }
}